package com.example.service.impl;

import com.example.constant.TokenConstant;
import com.example.pojo.entity.Admin;
import com.example.pojo.entity.User;
import com.example.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

/**
 * 与com.example.aspect.achieve.RedisListener任选一个
 */
@Service
public class RedisListenerServiceImpl {
    @Resource
    protected UserService userService;

    @Transactional
    public void handleMessage(String message) {
        if (message.startsWith(TokenConstant.TOKEN_REDIS+"user:")) {
            String userName = message.replace(TokenConstant.TOKEN_REDIS+"user:", "");
            User user =  new User();
            user.setUserName(userName);
            user.setIsLogin(0);
            userService.updateUser(user,false);
        }
        if (message.startsWith(TokenConstant.TOKEN_REDIS+"admin:")) {
            String userName = message.replace(TokenConstant.TOKEN_REDIS+"admin:", "");
            Admin admin =  new Admin();
            admin.setUserName(userName);
        }
        System.out.println("RedisListenerServiceImpl=>redis过期:"+message);

    }
}
